package com.android.Bean;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.android.DBTools.ADUS;
import com.android.DBTools.DBConnection;
import com.android.ObjectBean.ComRecruitObjectList;

import net.sf.json.JSONArray;

public class ComRecruitBean {
	public String recruitInfo() throws ClassNotFoundException, SQLException {
		String sql = "SELECT c.comRID,c.comRName,c.comRReq,c.comRCon,c.comRJob,"
				+ "c.comRDate,c.comRMon,c.comRPlace FROM comrecruit as c;";
		ResultSet rs = ADUS.selectData(sql);
		List<ComRecruitObjectList> list = new ArrayList<ComRecruitObjectList>();
		while (rs.next()) {
			ComRecruitObjectList cList = new ComRecruitObjectList();
			cList.setComRID(rs.getString(rs.findColumn("comRID")));
			cList.setComRName(rs.getString(rs.findColumn("comRName")));
			cList.setComRReq(rs.getString(rs.findColumn("comRReq")));
			cList.setComRCon(rs.getString(rs.findColumn("comRCon")));
			cList.setComRJob(rs.getString(rs.findColumn("comRJob")));
			cList.setComRDate(rs.getString(rs.findColumn("comRDate")));
			cList.setComRMon(rs.getString(rs.findColumn("comRMon")));
			cList.setComRPlace(rs.getString(rs.findColumn("comRPlace")));
			list.add(cList);
		}
		DBConnection.closeCon();
		JSONArray js = JSONArray.fromObject(list);
		return js.toString();
	}

	public void recruitInsert(String comRName, String comRReq, String comRCon, String comRJob, String comRMon,
			String comRDate, String comRPlace) throws ClassNotFoundException, SQLException {
		String sql = "INSERT INTO comrecruit (comRID,comRName,comRReq,comRCon,comRJob,comRMon,comRDate,comRPlace ) "
				+ "VALUES (NULL,\"" + comRName + "\",\"" + comRReq + "\",\"" + comRCon + "\",\"" + comRJob + "\",\"" + comRMon + "\",\""
				+ comRDate + "\",\"" + comRPlace + "\")";
		System.out.println(sql);
		ADUS.insertData(sql);
		DBConnection.closeCon();
	}
}
